package com.wen.business.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wen.business.mapper.ContentMapper;
import com.wen.business.service.ContentService;
import com.wen.common.pojo.account.Content;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class ContentSvcImpl implements ContentService {

    @Autowired
    private ContentMapper contentMapper;


    @Override
    public Page<Content> findContentPage(int pageNum, int pageSize, String search) {
        LambdaQueryWrapper<Content> wrapper = Wrappers.lambdaQuery();
        if (StrUtil.isNotBlank(search)) {
            wrapper.like(Content::getContentKeyword, search);
        }
        Page<Content> page = new Page<>(pageNum, pageSize);
        Page<Content> contentPage = contentMapper.selectPage(page, wrapper);

        return contentPage;
    }

    @Override
    public int add(Content content) {
        content.setContentDatetime(new Date());
        int i = contentMapper.insert(content);
        return i;
    }

    @Override
    public int update(Content content) {
        content.setModifiedTime(new Date());
        int i = contentMapper.updateById(content);
        return i;
    }

    @Override
    public int delete(Long id) {
        return contentMapper.deleteById(id);
    }
}
